//
//  CheckUpdateTask.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-6-26.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "CheckUpdateTask.h"
#import "CommonUtil.h"
#import "HttpUtil.h"
#import "StringUtil.h"

@implementation CheckUpdateTask

-(void)execute
{
    
    NSString *url = [[CommonUtil getDownloadUrl:@"updateclient/update_iphone.xml"]retain];
    if (![[self.params objectForKey:@"device"]isEqualToString:@"iphone"]) {
        url = [[CommonUtil getDownloadUrl:@"updateclient/update_ipad.xml"]retain];
    }
    
    NSString *bs = [HttpUtil getHttpBackString:url];
    
    NSString *remoteVersion = [StringUtil getXMLFormatedAttribute:bs :@"version"];
    
    NSString *info = [StringUtil getXMLFormatedAttribute:bs :@"updateinfo"];
    
    NSString *clientVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    
    remoteVersion  = [remoteVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
    
    int remoteInt = remoteVersion.intValue;
    
    clientVersion = [clientVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
    
    int clientInt = clientVersion.intValue;
    
    if (remoteInt>clientInt) {
        [self sendDataRefreshUI:[NSString stringWithFormat:@"<result>YES</result><info>%@</info>",info]];
    }
    else
    {
        [self sendDataRefreshUI:@"<result>NO</result>"];
    }
}



@end
